package com.hmall.common.domain;

import com.hmall.common.utils.CollUtils;
import lombok.Data;

import java.util.List;

@Data
public class MultiDelayMessage<T> {
    // 消息体
    private T data;
    // 记录延迟时间的集合
    private List<Long> delayWillis;

    public MultiDelayMessage(T data, List<Long> delayWillis) {
        this.data = data;
        this.delayWillis = delayWillis;
    }

    public static <T> MultiDelayMessage<T> of(T data, Long ... delayWillis) {
        return new MultiDelayMessage<>(data, CollUtils.newArrayList(delayWillis));
    }

    /**
     * 获取并移除下一个延迟时间
     * Returns: 队列中的第一个延迟时间
     */
    public Long removeNextDelay() {
        return delayWillis.remove(0);
    }

    public boolean hasNextDelay() {
        return !delayWillis.isEmpty();
    }
}